package com.test.reactor.actor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.typesafe.config.ConfigFactory;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Inbox;

/**
 * @author php
 * @date 2018/12/16
 * 创建ActorSystem，并将其放入到spring管理，初始化ApplicationContext
 */
@Configuration
public class ScanConfig {
    private final ApplicationContext context;
 
    @Autowired
    public ScanConfig(ApplicationContext context) {
        this.context = context;
    }
 
    @Bean
    public ActorSystem createSystem() {
        ActorSystem system = ActorSystem.create("system", ConfigFactory.load("my-application"));
        SpringExtProvider.getInstance().get(system).init(context);
        return system;
    }
    @Bean
    public Inbox createInbox(ActorSystem system) {
    	return Inbox.create(system);
    }
    @Bean(name="receiveActorRef")
    public ActorRef receiveActor(ActorSystem system) {
    	return system.actorOf(SpringExtProvider.getInstance().get(system).create("receiveActor"), "receiveActor");
    }
}
